/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var fieldLabel = new Array("序号","母线名称","母线电压等级(kV)","最高","最低","不合格时间(分)","不可调整","调整不良","不可调整","调整不良","总供电时间(分)","本月","季度","年累","原因分析","处理措施","完成情况","备注");
           
var fieldName=new Array("id","cdmc","dydj","zg","zd","bktz","tzbl","bktz","tzbl","zgdsj","by","jd","nl","yyfx","clcs","wcqk","bz");
var record_start = 0;
            
Ext.QuickTips.init();
var _pageSize = 20;
var store;
var theme = '告警';
var now = new Date();
var beginDate = now.format('Y-m');
var endDate=now.add(Date.MONTH,-1).format('Y-m');
        
var pointTypeStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {
        id: 'id', 
        name: 'name', 
        tableName: 't_pointType'
    },
    autoLoad: true,
    root: 'data',
    fields: ['id', 'name']
});

var pointTypeCombo = {
    xtype: 'combo',
    store: pointTypeStore,
    id: 'PointTypeCombo',
    displayField: 'name',
    valueField: 'id',
    hiddenName: 'pointTypeId',    
    mode: 'remote', 
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '监测点类型',
    emptyText: '请选择监测点类型...',
    selectOnFocus: true
}        

var pointTypeStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {
        id: 'id', 
        name: 'name', 
        tableName: 't_pointType2'
    },
    autoLoad: true,
    root: 'data',
    fields: ['id', 'name']
});

var pointTypeCombo2 = {
    xtype: 'combo',
    store: pointTypeStore,
    id: 'PointTypeCombo2',
    displayField: 'name',
    valueField: 'id',
    hiddenName: 'pointType2Id',    
    mode: 'remote', 
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '城农网类别',
    emptyText: '请选择城农网类别...',
    selectOnFocus: true
}

var dateFrom = {
    xtype: 'datefield',
    id: 'DateFrom',
    format: 'Y年m月',
    width: 150,
    value:now.add(Date.MONTH,-1),
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m');
            store.baseParams.beginDate = beginDate;
        }
    }  
}

var dateTo={
    xtype: 'datefield',
    id: 'DateTo',
    format: 'Y年m月',
    width: 150,
    value:now,
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m');
            store.baseParams.beginDate = beginDate;
        }
    }
}

function downloadExcel(){
    var datefrom=DateFrom.value;
    var dateto=DateTo.value;
    var PointType = PointTypeCombo.value;
    var PointType2 = PointTypeCombo2.value;
    params={
        PointType:PointType,
        PointType2:PointType2,
        datefrom:datefrom,
        dateto:dateto
    };
    var encodeParams = Ext.urlEncode(params);
    open('../../servlet/ExcelFileCreate?'+encodeParams);
}

function buildWindow(){

    store=new Ext.data.JsonStore({               
        //data: [
        //       ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17']
        //]
        url: "../../servlet/report/gridvoltagepoint",
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: true,
        baseParams: {
            beginDate: beginDate, 
            endDate: endDate
        }
    });
    colModel= new Ext.grid.ColumnModel({
        columns: [
        new Ext.grid.RowNumberer({
            header : fieldLabel[0],
            align: 'center', 
            width : 40,
            renderer: function (value, metadata, record, rowIndex) {
                return record_start + 1 + rowIndex;
            }
        }),

        {
            header: fieldLabel[1], 
            width: 100, 
            dataIndex: fieldName[1], 
            align: 'center'
        },

        {
            header: fieldLabel[2], 
            width: 100, 
            dataIndex: fieldName[2], 
            align: 'center'
        },

        {
            header: fieldLabel[3], 
            width: 100, 
            dataIndex: fieldName[3], 
            align: 'center'
        },

        {
            header: fieldLabel[4], 
            width: 100, 
            dataIndex: fieldName[4], 
            align: 'center'
        },

        {
            header: fieldLabel[5], 
            width: 100, 
            dataIndex: fieldName[5], 
            align: 'center'
        },

        {
            header: fieldLabel[6], 
            width: 100, 
            dataIndex: fieldName[6], 
            align: 'center'
        },

        {
            header: fieldLabel[7], 
            width: 100, 
            dataIndex: fieldName[7], 
            align: 'center'
        },

        {
            header: fieldLabel[8], 
            width: 100, 
            dataIndex: fieldName[8], 
            align: 'center'
        },

        {
            header: fieldLabel[9], 
            width: 100, 
            dataIndex: fieldName[9], 
            align: 'center'
        },

        {
            header: fieldLabel[10], 
            width: 100, 
            dataIndex: fieldName[10], 
            align: 'center'
        },

        {
            header: fieldLabel[11], 
            width: 100, 
            dataIndex: fieldName[11], 
            align: 'center'
        },

        {
            header: fieldLabel[12], 
            width: 100, 
            dataIndex: fieldName[12], 
            align: 'center'
        },

        {
            header: fieldLabel[13], 
            width: 100, 
            dataIndex: fieldName[13], 
            align: 'center'
        },

        {
            header: fieldLabel[14], 
            width: 100, 
            dataIndex: fieldName[14], 
            align: 'center'
        },

        {
            header: fieldLabel[15], 
            width: 100, 
            dataIndex: fieldName[15], 
            align: 'center'
        },

        {
            header: fieldLabel[16], 
            width: 100, 
            dataIndex: fieldName[16], 
            align: 'center'
        },
        ],
        defaultSortable: true,
        rows: [
        [
        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            header: '电压变化范围(kV)', 
            colspan: 2, 
            align: 'center'
        }, 

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            header: '越上限时间(分)', 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            header: '越下限时间(分)', 
            colspan: 2, 
            align: 'center'
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            header:'合格率(%)', 
            colspan: 3, 
            align: 'center'
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100, 
            rowspan: 1
        },

        {
            width: 100,     
            rowspan: 1
        },
        ], 
        ]
    });

   
    
    var grid = new Ext.grid.GridPanel({
        title: '电网电压逐点统计表',
        store: store,
        colModel:colModel,
        enableColumnMove: false,
        viewConfig: {
            forceFit: false
        },
        plugins: [new Ext.ux.plugins.GroupHeaderGrid()],
        loadMask: true,
        tbar: new Ext.Toolbar([
        {
            text: "选择开始日期：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        dateFrom,
        '-',
        {
            text: "选择结束日期：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        dateTo,
        '-',
        {
            text: "监测点类型：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        
        pointTypeCombo, 
    
        
        '-',
        {
            text: "电网类型：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        pointTypeCombo2, 
        '-',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                store.load({
                    params: {
                        start: 0, 
                        limit: _pageSize
                    }
                });
            }
        },
        '-',
        {
            xtype: 'button',
            text: '导出',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: downloadExcel
        },
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        })
    });
    store.load({
        params: {
            start: 0, 
            limit: _pageSize
        }
    });
    
    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
        grid
        ]
    });
}
Ext.onReady(buildWindow);  